/**
 * @copyright (c) 2024, MacRsh
 *
 * @license SPDX-License-Identifier: Apache-2.0
 *
 * @date 2024-08-08    MacRsh       First version
 */

#ifndef __ATOMIC_H__
#define __ATOMIC_H__

#include <errno.h>
#include <malloc.h>
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * @addtogroup Atomic
 * @{
 */

/**
 * @brief Represents an atomic integer.
 */
typedef int Atomic_t;

void atomic_init(Atomic_t *atomic, Atomic_t value);
void atomic_deinit(Atomic_t *atomic);
Atomic_t *atomic_new(Atomic_t value);
void atomic_del(Atomic_t *atomic);
Atomic_t atomic_load(Atomic_t *atomic);
void atomic_store(Atomic_t *atomic, Atomic_t value);
Atomic_t atomic_exchange(Atomic_t *atomic, Atomic_t value);
Atomic_t atomic_fetch_add(Atomic_t *atomic, Atomic_t value);
Atomic_t atomic_fetch_sub(Atomic_t *atomic, Atomic_t value);
Atomic_t atomic_fetch_and(Atomic_t *atomic, Atomic_t value);
Atomic_t atomic_fetch_or(Atomic_t *atomic, Atomic_t value);
bool atomic_compare_exchange(Atomic_t *atomic, Atomic_t old_value,
                             Atomic_t new_value);

/** @} */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __ATOMIC_H__ */
